layui.define(['form','table'], function(exports){
  var $ = layui.$,form = layui.form,table = layui.table;

  var typeId = $('input[name="id"]').val();

  table.render({
    elem: '#LAY-table'
    ,url: layui.setter.webRoot + '/agent/type/user/list.data'
      ,where:{typeId:typeId}
    ,method: 'post'
    ,parseData: function (res) {
        return {
            "code": res.code,
            "msg": res.msg,
            "count": res.body.total,
            "data": res.body.data
        };
    }
    ,response: {statusCode: 200}
    ,cols: [[
          {field: 'userId', title: '用户ID'}
          ,{field: 'name', title: '用户名称',templet:function (record){
                  return record.user.name;
              }}
		  ,{field: 'name', title: '用户手机号',templet:function (record){
            	return record.user.phone;
           }}
          ,{field: 'createDate', title: '创建时间'}
          ,{title: '操作', width: 80, align:'center', fixed: 'right', templet:function(record){
              var html = '';
              html = html + '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delUser">删除</a>';
              return html;
              }}
    ]]
    ,page: true
    ,height: 'full-220'
    ,text: '对不起，加载出现异常！'
  });
  
  //事件
  var active = {
      delUser:function(obj){
          layer.confirm('确定要移除该代理吗？', function(index){
              $.ajax({
                  type: "post",
                  url: layui.setter.webRoot + '/agent/type_rel/del.do',
                  data:{typeId:typeId,userId:obj.data.userId},
                  dataType:"json",
                  success:function(res){
                      if(res.code == 200){
                          obj.del();
                      }else{
                          layer.msg(res.msg,{icon: 5});
                      }
                  }
              });
              layer.close(index);
          });
      }
  };
  
  $('.layui-btn.LAY-btn-fun').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
  
  table.on('tool(LAY-table)', function(obj){
  	var type = obj.event ;
   	active[type] ? active[type].call(this,obj) : '';
  });
  
  exports('agent_type_info', {})
});